import { fileURLToPath, URL } from 'node:url';
import qiankun from 'vite-plugin-qiankun';
import { defineConfig } from 'vite';
import legacy from '@vitejs/plugin-legacy';
import vue2 from '@vitejs/plugin-vue2';
import { name as packageName } from './package.json';

export default defineConfig({
  plugins: [
    vue2(),
    qiankun(packageName, {
      useDevMode: true
    }),
    legacy({
      targets: ['ie >= 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime']
    })
  ],
  // 配置前端服务地址和端口
  server: {
    host: '0.0.0.0',
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    port: 7076,
    // 是否开启 https
    https: false,
    open: false
    // 设置反向代理，跨域
    // proxy: {
    //   '/ft': {
    //     // 后台地址
    //     target: 'http://10.160.86.118:9010/',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/ft/, '')
    //   }
    // }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
});
